window.addEventListener('workEvent', function(event) {
	var detail = event.detail;
	setTimeout(function() {
		loadData();

	}, 500)

});



var mask = null;
var login_user = null
$(function() { // 初始化内容
	mui.plusReady();
	mask = mui.createMask(); //遮罩层
	login_user = JSON.parse(localStorage.getItem('loginUser'));
	mui.init();
	datetime_init();
	setTimeout(function() {
		loadData();
	}, 300)

})




function loadData() {
	//loadknockdownnum();
	loaddiscountnum();
	loadRefundnum();
	loadSiteUseFee();
	loadServiceResource();
	loadPublicResource();
}

function openKnockdownRecordList() {



	window.location.href = "knockdownRecordList.html"
}


function openRefundRecordList() {

	window.location.href = "refundRecordList.html"
}

function openDiscountsRecordList() {

	window.location.href = "discountRecordList.html"

}

function openUpAllotResourceList() {

	window.location.href = "upAllotResourceList.html"
}

function openSiteUseFeeList() {
	window.location.href = "siteUseFeeList.html"
}

function openStatistics() {

	window.location.href = "statistics.html"

}

function openPublicResourceList() {

	window.location.href = "publicResourceList.html"

}

function openResourceAdultList (){
	
	window.location.href = "resourceAdultList.html"
	
}



function loaddiscountnum() {

	var data = {};
	// data['createdatestart'] = startCurrentMonth();
	// data['createdateend'] = endCurrentMonth();
	data['page'] = 1;
	data['rows'] = 20;
	data['schoolid'] = login_user.schoolid;
	data['auditstatis'] = "未审核";
	console.log("优惠审批====" + JSON.stringify(data));
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "POST",
		url: serverip + "fxxz/yhspGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(data) {
			console.log("数量返回信息" + JSON.stringify(data));

			mask.close(); //显示遮罩层\
			var records = data.records;
			jQuery("#s3").text(records);

		},

		error: function(e) {

			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("数量错误" + JSON.stringify(e));
		}
	});
}



function loadRefundnum() {

	var data = {};
	// data['donetimestart'] = startCurrentMonth();
	// data['donetimeend'] = endCurrentMonth();
	data['page'] = 1;
	data["rows"] = 20;
	data['xzauditstatus'] = "审核中";
	data['type'] = "退款";
	data['schoolid'] = login_user.schoolid;
	console.log("退款记录审批=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxxz/tkspGrid",
		contentType: 'application/json',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {

			mask.close(); //显示遮罩层 	  
			console.log("退款记录列表====" + JSON.stringify(res));

			var records = res.records;
			jQuery("#s2").text(records);

		},
		error: function(e) {

			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}




function loadServiceResource() {
	
	var data = {};
	data['page'] = '1';
	data["rows"] = 20;
	data['type'] = '0';
	data['sort'] = "stucomingdate"
	data['schoolid'] = login_user.schoolid;
	data['stucomingdatestart'] = startCurrentMonth()
	data['stucomingdateend'] = endCurrentMonth()
	console.log("待分配资源列表=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxxz/kfGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			mask.close(); //显示遮罩层
			console.log("待分配资源" + JSON.stringify(res));
			var records = Number(res.records);
			jQuery("#s5").text(records);
			
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}

function loadSiteUseFee() {

	var data = {};
	data['rows'] = 20
	data['page'] = 1
	data['schoolid'] = login_user.schoolid
	data['xzauditstatus'] = "审核中"
	console.log("场地费审批====" + JSON.stringify(data));
	jQuery.ajax({
		headers: {
			'Authorization': login_user.token
		},
		type: "POST",
		url: serverip + "fxxz/cdfAuditGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层
		},
		success: function(data) {
			console.log("数量返回信息" + JSON.stringify(data));

			mask.close(); //显示遮罩层\
			var records = data.records;
			jQuery("#s4").text(records);

		},

		error: function(e) {
			console.log("数量错误" + JSON.stringify(e));
			mask.close(); //显示遮罩层
			var msg = e.responseJSON.message;
			var code = e.responseJSON.status;
			mui.alert('错误编码' + code + "\n" + "错误信息:" + msg);

		}
	});
}


function loadPublicResource() {
	var data = {};
	data['page'] = 1;
	data["rows"] = 20;

	data['sort'] = "id"
	data['schoolid'] = login_user.schoolid;
	console.log("公共资源列表=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxxz/ggGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			
			mask.close(); //显示遮罩层 	  
			console.log("记录列表" + JSON.stringify(res));
			var records = res.records;
			jQuery("#s6").text(records);
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}
